package pl.maciejziarko.mshare.service.processors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import pl.maciejziarko.mshare.domain.Account;
import pl.maciejziarko.mshare.domain.Resource;
import pl.maciejziarko.mshare.security.SecurityService;

/**
 * @author Maciej Ziarko
 */
@Component
public class ResourceProcessor implements Processor<Resource> {

    private SecurityService securityService;

    @Autowired
    public ResourceProcessor(SecurityService securityService) {
        this.securityService = securityService;
    }

    @Override
    public Resource process(Resource resource) throws ProcessingException {
        //Setting owner:
        resource.setOwner(new Account(securityService.getUsername()));

        //Setting size:
        resource.setSize(resource.getData().length);

        return resource;
    }
}
